package org.example.modules.user.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Description Commsult
 * @Author xiaotian
 * @Date 2025-03-11
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Commsult<T> {

    private int code;
    private String msg;
    private T data;

    // 成功响应的静态方法
    public static <T> Commsult<T> success(T data) {
        return new Commsult<>(200, "success", data);
    }

    // 成功响应的静态方法，允许自定义消息
    public static <T> Commsult<T> success(String msg, T data) {
        return new Commsult<>(200, msg, data);
    }

    // 失败响应的静态方法
    public static <T> Commsult<T> fail(int code, String msg) {
        return new Commsult<>(code, msg, null);
    }

    // 失败响应的简化静态方法，默认错误码为500
    public static <T> Commsult<T> fail(String msg) {
        return new Commsult<>(500, msg, null);
    }
}